package DMSXL._2024.BinaryTrees;

import java.util.LinkedList;
import java.util.Queue;

public class maxDepth {
    public static void main(String[] args) {

    }
    public int maxDepth(TreeNode root){
        Queue<TreeNode> queue = new LinkedList<>();
        if(root == null){
            return 0;
        }
        queue.offer(root);
        int len = 0;
        while (!queue.isEmpty()){
            int n = queue.size();
            len++;
            for (int i = 0; i < n; i++) {
                TreeNode cur = queue.poll();
                if(cur.left != null){
                    queue.offer(cur.left);
                }
                if(cur.right != null){
                    queue.offer(cur.right);
                }

            }


        }
        return len;
    }
}
